/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.TextArea;
import java.awt.TextComponent;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SpringLayout;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author brandonmckune
 */
public class ClientController implements ActionListener, ChangeListener, MouseListener, MouseWheelListener{
    
    private ClientFrame clientF = null;
    private static ClientController controller = null;
    private Connection conn = null; 
    private static int NUM_COLUMNS = 40;
    private static String INTERACTION_INPUT = "<------||New Interaction||------>\n";
    private static String INTERACTION_END =   "<------||End Interaction||------>\n"; 
    private int MAP_WIDTH = 68;
    private int MAP_HEIGHT = 50;
    private int MAP_FIELDS = 6;
    private String nickName = null;
    private InetAddress inet = null;
	private boolean [] canShoot = new boolean [6];
	private boolean changeAmmoType = true;
	
	private int numberOfPlayers = 0;
	private String myName = null;
	    
    private int weaponSelected = 1;    
    private Vector<ImageApplet> maps = new Vector<ImageApplet>();
    
    //private ImageIcon land = null;
    
    
    /**
     * Constructor:  This method allows the Frame class to pass a reference
     * to itself into the Controller classes methods.  Thus, allowing for the
     * controller class to "control" the frames.  
     * @param cf ClientFrame object.
     */
    private ClientController(ClientFrame cf)
    {
        this.clientF = cf;
        this.startClient();
		
			for(int i = 0; i < 6; i++){
				canShoot[i] = true;
			}
    }
    
    public static synchronized ClientController getInstance(ClientFrame cf)
    {
    	if(controller == null)
    	{
    		controller = new ClientController(cf);
    	}
    	return controller;
    }
    
    public void startClient()
    {
    	this.setGameEnabled(false);
    	this.setChatEnabled(false);
    	this.setIsConnected(false);
    	this.setConnectionEnabled(true);
    	this.setPlayersEnabled(false);
    	this.setYAxisScrollMenu();
    	this.setXAxisScrollMenu();
    	this.setBombScrollMenu();
    	//this.setMapElements();
    	
        clientF.getClientsServerInteractionTextArea().setEditable(false);
        clientF.getClientChatTextArea().setEditable(false);
        clientF.getClientGameInteractionTextArea().setEditable(false);
        clientF.setTitle("Team One's Distributed Project");
        clientF.getClientPlayerTurnLabel().setVisible(false);
        
        this.defaultMap();
        for (int i = 0; i < 6; i++)
        {
        	maps.get(i).addMouseListener(this);
        	maps.get(i).addMouseWheelListener(this);
        }
    }
    
    public void setGameEnabled(boolean isEnabled)
    {
	 	
		  	clientF.getClientTabPlayer1().setVisible(false);
  		  	clientF.getClientTabPlayer2().setVisible(false);
   	 	clientF.getClientTabPlayer3().setVisible(false);
   	 	clientF.getClientTabPlayer4().setVisible(false);
   	 	clientF.getClientTabPlayer5().setVisible(false);
   	 	clientF.getClientTabPlayer6().setVisible(false);
    	clientF.getClientBombTypeLabel().setEnabled(isEnabled);
    	clientF.getClientBombTypeScrollPanel().setEnabled(isEnabled);
    	clientF.getClientPlayButton().setEnabled(isEnabled);
    	clientF.getClientShipPanel().setEnabled(false);
    	clientF.getClientXAxisLabel().setEnabled(false);
    	clientF.getClientXAxisScrollPanel().setEnabled(false);
    	clientF.getClientYAxisLabel().setEnabled(false);
    	clientF.getClientYAxisScrollPanel().setEnabled(false);
		clientF.getClientShipPanel().setVisible(false);
		clientF.getClientXAxisLabel().setVisible(false);
		clientF.getClientXAxisScrollPanel().setVisible(false);
		clientF.getClientYAxisLabel().setVisible(false);
		clientF.getClientYAxisScrollPanel().setVisible(false);
    	clientF.getClientTurnPenaltyLabel().setEnabled(isEnabled);
    	clientF.getClientTurnPenaltyNumLabel().setEnabled(isEnabled);
    	
    	//disables && enables map tabbed frame w/ player maps.
    	clientF.getClientMapTabbedPane().setVisible(isEnabled);
		
		numberOfPlayers = clientF.getClientPlayerTextList().getItemCount();
		System.out.println("NUM OF PLAYERS ->" + numberOfPlayers);
		
		switch(numberOfPlayers){
		case 2:
		   clientF.getClientTabPlayer1().setVisible(isEnabled);
    		clientF.getClientTabPlayer2().setVisible(isEnabled);
   	 	clientF.getClientTabPlayer3().setVisible(false);
   	 	clientF.getClientTabPlayer4().setVisible(false);
   	 	clientF.getClientTabPlayer5().setVisible(false);
   	 	clientF.getClientTabPlayer6().setVisible(false);
			clientF.getClientMapTabbedPane().repaint();
			break;
		case 3:
		   clientF.getClientTabPlayer1().setVisible(isEnabled);
    		clientF.getClientTabPlayer2().setVisible(isEnabled);
    		clientF.getClientTabPlayer3().setVisible(isEnabled);
			break;
		case 4:
		   clientF.getClientTabPlayer1().setVisible(isEnabled);
    		clientF.getClientTabPlayer2().setVisible(isEnabled);
    		clientF.getClientTabPlayer3().setVisible(isEnabled);
    		clientF.getClientTabPlayer4().setVisible(isEnabled);
			break;
		case 5:
		   clientF.getClientTabPlayer1().setVisible(isEnabled);
    		clientF.getClientTabPlayer2().setVisible(isEnabled);
    		clientF.getClientTabPlayer3().setVisible(isEnabled);
    		clientF.getClientTabPlayer4().setVisible(isEnabled);
    		clientF.getClientTabPlayer5().setVisible(isEnabled);
			break;
		case 6:
		  	clientF.getClientTabPlayer1().setVisible(isEnabled);
  		  	clientF.getClientTabPlayer2().setVisible(isEnabled);
   	 	clientF.getClientTabPlayer3().setVisible(isEnabled);
   	 	clientF.getClientTabPlayer4().setVisible(isEnabled);
   	 	clientF.getClientTabPlayer5().setVisible(isEnabled);
   	 	clientF.getClientTabPlayer6().setVisible(isEnabled);
			break;
		}
    }
	
	public void disableTabPlayer(int tabbedPane){
		if(tabbedPane > 6 || tabbedPane < 0){
			System.err.println("ClientController::disableTabPlayer -> invalid parameter passed.");
			//throw new InvalidParameterException();
		}else{
			switch(tabbedPane){
			case 0:
				clientF.getClientTabPlayer1().setEnabled(false);
				canShoot[tabbedPane] = false;
				break;
			case 1:
				clientF.getClientTabPlayer2().setEnabled(false);
				canShoot[tabbedPane] = false;
				break;
			case 2:
				clientF.getClientTabPlayer3().setEnabled(false);
				canShoot[tabbedPane] = false;
				break;
			case 3:
				clientF.getClientTabPlayer4().setEnabled(false);
				canShoot[tabbedPane] = false;
				break;
			case 4:
				clientF.getClientTabPlayer5().setEnabled(false);
				canShoot[tabbedPane] = false;
				break;
			case 5:
				clientF.getClientTabPlayer6().setEnabled(false);
				canShoot[tabbedPane] = false;
				break;
			}
		}
	}
	
	public void resetFireAbility(){
		for(int i = 0; i < canShoot.length; i++){
			canShoot[i] = true;
		}
		
		changeAmmoType = true;
	}
    
    public void setChatEnabled(boolean isEnabled)
    {
    	clientF.getClientChatTextArea().setEnabled(isEnabled);
    	clientF.getClientChatTextInputArea().setEnabled(isEnabled);
    	clientF.getClientSubmitChatButton().setEnabled(isEnabled);
    }
    
    public void setConnectionEnabled(boolean isEnabled)
    {
    	clientF.getClientIpInputTextbox().setEnabled(isEnabled);
    	clientF.getClientIpLabel().setEnabled(isEnabled);
    	clientF.getClientNicknameInputTextbox().setEnabled(isEnabled);
    	clientF.getClientNickNameLabel().setEnabled(isEnabled);
    	
    	if(isEnabled)
    	{
    		clientF.getClientStatusLabel().setText("Disconnected");
    	}
    	else
    	{
    		clientF.getClientStatusLabel().setText("Connected");
    	}
    	
    	clientF.getClientStartGameMenuItem1().setEnabled(!isEnabled);
    	setChatEnabled(!isEnabled);
    }
    
    public void setPlayersEnabled(boolean isEnabled)
    {
    	clientF.getClientPlayerListLabel().setEnabled(isEnabled);
    	clientF.getClientPlayerTextList().setEnabled(isEnabled);
    }
    
    public void setMapElements()
    {
    
		Vector<String> players = Connection.getInstance().getPlayers();
    	

    		for(int i = 0; i < players.size(); i++)
    		{
    			clientF.getClientMapTabbedPane().setTitleAt(i, players.get(i));
    		}
    }
	
	public void updatePlayerList(){
	Vector<String> temp = Connection.getInstance().getPlayers();
	 	for(int i =0; i < temp.size(); i++){
			ClientFrame.getInstance().getClientPlayerTextList()
				.add(temp.get(i));
				
				System.out.println(temp.get(i));
		}
		
		ClientFrame.getInstance().getClientPlayerTextList().repaint();
	}
    
    public void connectServer()
    {
    	
    	nickName = clientF.getClientNicknameInputTextbox().getText().toString();
    	String address = clientF.getClientIpInputTextbox().getText().toString();
    	
    	if(address.length() != 0 && nickName.length() != 0)
    	{
    	    Connection.getInstance().setUser(nickName);
    	    Connection.getInstance().setServer(address);
    	    boolean success = Connection.getInstance().connect();
    	    if(success)
    	    {
    	    	setConnectionEnabled(false);
    	    	clientF.getClientConnectServerButton().setText("Disconnect");
    	    	clientF.getClientTabPlayer1().paintImmediately(new Rectangle());
				clientF.getClientPlayerTextList().setEnabled(true);
				updatePlayerList();
				myName = Connection.getInstance().getNickName();
    	    }
    	    else
    	    {
    	    	clientF.getClientTabbedFrame().setForegroundAt(1, Color.RED);
    	    	boolean hasEnded = false;
    	    	printToInteraction("Login unsuccessful", "");
    	    }
    	    	
    	}//End of good Connection
    	else
    	{
    		clientF.getClientTabbedFrame().setForegroundAt(1, Color.RED);
    		boolean hasEnded = false;
    		
    		if(address.length() == 0)
    		{
    			clientF.getClientsServerInteractionTextArea().append(
    					INTERACTION_INPUT + "Invalid Ip Address -> null\n"
    					+ "  Please enter valid ip.\n");
    				if(nickName.length() == 0)
    				{
    					clientF.getClientsServerInteractionTextArea().append(
    	    					"Enter a nickname.\n" + INTERACTION_END);
    					hasEnded = true;
    				}
    			if(!hasEnded)
    			{
    				clientF.getClientsServerInteractionTextArea().append(INTERACTION_END);
    			}
    		}
    		else
    		{
    			clientF.getClientsServerInteractionTextArea().append(
    					INTERACTION_INPUT + "Enter a nickname.\n" + INTERACTION_END);
    		}//end null
    	}//End of bad connection Else.
    }
    
    public void disconnectServer()
    {
    	
    	setConnectionEnabled(true);
    	clientF.getClientConnectServerButton().setText("Connect");
    	
    	Connection.getInstance().endConnection();
    	for(int i = 0; i < 6; i++)
    	{
    		clientF.getClientMapTabbedPane().setTitleAt(i, "Player" + i);
    	}
    	
    	setGameEnabled(false);
		ClientFrame.getInstance().getClientPlayerTextList().removeAll();
    }//End disconnect server function.
    
    
    
    /**
     * This method allows the Client code to tell the GUI whether or
     * not the socket connection is still active.  This also forces the
     * redraw/change of the gui element indicating this connection.
     * @param connect Boolean whether or not this is connected.
     */
    public void setIsConnected(boolean connect)
    {
    	
    	boolean temp = Connection.getInstance().isConnected();
    	
    	if(temp)
    	{
    		clientF.getClientStatusLabel().setText("Connected");
    	}
    	else{
    		clientF.getClientStatusLabel().setText("Disconnected");
    	}
    }
    
    public void printToChat(String msg, String time)
    {
    	//prints to chat
    	String chat = "[" + time + "]" + nickName + ":->" + msg + "\n";
    	clientF.getClientChatTextArea().append(chat.trim() + "\n");
    }
    
    public void printToInteraction(String msg, String time)
    {
    	clientF.getClientsServerInteractionTextArea().append(
    			INTERACTION_INPUT + msg + "\n" + INTERACTION_END);
    }
    
    /**
     * Implemented Method from ActionListener class.  This allows 
     * the controller class to catch all ActionEvents and handle them
     * accordingly.  
     */
    public void actionPerformed(ActionEvent ae)
    {
    	if(ae.getActionCommand().equalsIgnoreCase(clientF.getClientExitMenuItem1().getText()))
    	{
    		System.exit(1);
    	}//end Exit
    	else if(ae.getActionCommand().equalsIgnoreCase(clientF.getClientConnectServerButton().getText()))
    			{
    		
    		String button = clientF.getClientConnectServerButton().getText();
    		
    		if(button.equalsIgnoreCase("Connect"))
    		{
    			this.connectServer();
    		}
    		else{
    			this.disconnectServer();
    		}
    	}
    	else if(ae.getActionCommand().equalsIgnoreCase(
    			clientF.getClientStartGameMenuItem1().getText()))
    			{
    		setGameEnabled(true);
    		setMapElements();
    		clientF.getClientStartGameMenuItem1().setEnabled(false);
    	}
    	else if(ae.getActionCommand().equalsIgnoreCase(clientF.getClientSubmitChatButton().getText()))
        {
    		String chat = clientF.getClientChatTextInputArea().getText();
    		
    		if(chat.length() != 0)
    		{
    			Connection.getInstance().sendChat(chat);
    			clientF.getClientChatTextInputArea().setText("");
    		}
    		else
    		{
    			//do nothing
    		}
    	}
    		
    }
   
	public void stateChanged(ChangeEvent e)
	{
		// TODO Auto-generated method stub
		JTabbedPane tempPane = (JTabbedPane)e.getSource();
		
		System.out.println(tempPane.getSelectedComponent());
		System.out.println(tempPane.getSelectedIndex());
		
		if(tempPane.getSelectedComponent().toString().contains("jScrollPane2")){
			
			//The getSelectedIndex starts at 0.
			switch(tempPane.getSelectedIndex()){
			case 0:
				break;
			case 1:
	    		clientF.getClientTabbedFrame().setForegroundAt(1, Color.black);
	    		break;
			case 2:
				break;
			}
			
		}
		else if(tempPane.getSelectedComponent().toString().contains("clientTabPlayer"))
		{
			
			//The getSelectedIndex starts at 1.
			//each tab is 668 X 456 pixels
			SpringLayout tempLayout = new SpringLayout();
			JPanel temp = null;
			
			
			
			switch(tempPane.getSelectedIndex()){
			case 0:
					temp = clientF.getClientTabPlayer1();
					temp.setLayout(tempLayout);
					drawMapPanel(tempLayout, temp, 0);
					break;
			case 1:
				temp = clientF.getClientTabPlayer2();
				temp.setLayout(tempLayout);
				drawMapPanel(tempLayout, temp, 1);
				break;
			case 2:
				temp = clientF.getClientTabPlayer3();
				temp.setLayout(tempLayout);
				drawMapPanel(tempLayout, temp, 2);
				break;
			case 3:
				temp = clientF.getClientTabPlayer4();
				temp.setLayout(tempLayout);
				drawMapPanel(tempLayout, temp, 3);
				break;
			case 4:
				temp = clientF.getClientTabPlayer5();
				temp.setLayout(tempLayout);
				drawMapPanel(tempLayout, temp, 4);
				break;
			case 5:
				temp = clientF.getClientTabPlayer6();
				temp.setLayout(tempLayout);
				drawMapPanel(tempLayout, temp, 5);
				break;
			}
		}
	}

	public void drawMapPanel(SpringLayout tempLayout, JPanel temp, int index) {
		temp.add(maps.get(index));
			tempLayout.putConstraint(SpringLayout.WEST, maps.get(index), 1, SpringLayout.WEST, temp);
			tempLayout.putConstraint(SpringLayout.EAST, maps.get(index), -1, SpringLayout.EAST, temp);
			tempLayout.putConstraint(SpringLayout.NORTH, maps.get(index), 1, SpringLayout.NORTH, temp);
			tempLayout.putConstraint(SpringLayout.SOUTH, maps.get(index), -1, SpringLayout.SOUTH, temp);
	}
    
    
    private void setBombScrollMenu()
    {
        clientF.getClientBombTypeScrollPanel().removeAllItems();
        clientF.getClientBombTypeScrollPanel().addItem("54 Cal. Mark 7 -0-");
        clientF.getClientBombTypeScrollPanel().addItem("16\" Mark 7 -3-");
        clientF.getClientBombTypeScrollPanel().addItem("Cruise Missle -5-");
        clientF.getClientBombTypeScrollPanel().setVisible(true);
        clientF.getClientBombTypeScrollPanel().setEnabled(false);
    }
    
    private void setYAxisScrollMenu()
    {
    	clientF.getClientYAxisScrollPanel().removeAllItems();
    	clientF.getClientYAxisScrollPanel().addItem('A');
    	clientF.getClientYAxisScrollPanel().addItem('B');
    	clientF.getClientYAxisScrollPanel().addItem('C');
    	clientF.getClientYAxisScrollPanel().addItem('D');
    	clientF.getClientYAxisScrollPanel().addItem('E');
    	clientF.getClientYAxisScrollPanel().addItem('F');
    	clientF.getClientYAxisScrollPanel().addItem('G');
    	clientF.getClientYAxisScrollPanel().addItem('H');
    	clientF.getClientYAxisScrollPanel().addItem('I');
    	clientF.getClientYAxisScrollPanel().addItem('J');
    	clientF.getClientYAxisScrollPanel().addItem('K');
    	clientF.getClientYAxisScrollPanel().addItem('L');
    	clientF.getClientYAxisScrollPanel().addItem('M');
    	clientF.getClientYAxisScrollPanel().addItem('N');
    	clientF.getClientYAxisScrollPanel().addItem('O');
    	clientF.getClientYAxisScrollPanel().addItem('P');
    	clientF.getClientYAxisScrollPanel().addItem('Q');
    	clientF.getClientYAxisScrollPanel().addItem('R');
    	clientF.getClientYAxisScrollPanel().addItem('S');
    	clientF.getClientYAxisScrollPanel().addItem('T');
    	clientF.getClientYAxisScrollPanel().addItem('U');
    	clientF.getClientYAxisScrollPanel().addItem('V');
    	clientF.getClientYAxisScrollPanel().addItem('W');
    	clientF.getClientYAxisScrollPanel().addItem('X');
    	clientF.getClientYAxisScrollPanel().addItem('Y');
    	clientF.getClientYAxisScrollPanel().addItem("Z");
    	clientF.getClientYAxisScrollPanel().addItem("AA");
    	clientF.getClientYAxisScrollPanel().addItem("AB");
    	clientF.getClientYAxisScrollPanel().addItem("AC");
    	clientF.getClientYAxisScrollPanel().addItem("AD");
    	clientF.getClientYAxisScrollPanel().addItem("AE");
    	clientF.getClientYAxisScrollPanel().addItem("AF");
    	clientF.getClientYAxisScrollPanel().addItem("AG");
    	clientF.getClientYAxisScrollPanel().addItem("AH");
    	clientF.getClientYAxisScrollPanel().addItem("AI");
    	clientF.getClientYAxisScrollPanel().addItem("AJ");
    	clientF.getClientYAxisScrollPanel().addItem("AK");
    	clientF.getClientYAxisScrollPanel().addItem("AL");
    	clientF.getClientYAxisScrollPanel().addItem("AM");
    	clientF.getClientYAxisScrollPanel().addItem("AN");
    	clientF.getClientYAxisScrollPanel().addItem("AO");
    	clientF.getClientYAxisScrollPanel().addItem("AP");
    	clientF.getClientYAxisScrollPanel().addItem("AQ");
    	clientF.getClientYAxisScrollPanel().addItem("AR");
    	clientF.getClientYAxisScrollPanel().addItem("AS");
    	clientF.getClientYAxisScrollPanel().addItem("AT");
    	clientF.getClientYAxisScrollPanel().addItem("AU");
    	clientF.getClientYAxisScrollPanel().addItem("AV");
    	clientF.getClientYAxisScrollPanel().addItem("AW");
    	clientF.getClientYAxisScrollPanel().addItem("AX");
    	clientF.getClientYAxisScrollPanel().addItem("AY");
    	clientF.getClientYAxisScrollPanel().addItem("AZ");
    	clientF.getClientYAxisScrollPanel().addItem("BA");
    	clientF.getClientYAxisScrollPanel().addItem("BB");
    	clientF.getClientYAxisScrollPanel().addItem("BC");
    	clientF.getClientYAxisScrollPanel().addItem("BD");
    	clientF.getClientYAxisScrollPanel().addItem("BE");
    	clientF.getClientYAxisScrollPanel().addItem("BF");
    	clientF.getClientYAxisScrollPanel().addItem("BG");
    	clientF.getClientYAxisScrollPanel().addItem("BH");
    	clientF.getClientYAxisScrollPanel().addItem("BI");
    	clientF.getClientYAxisScrollPanel().addItem("BJ");
    	clientF.getClientYAxisScrollPanel().addItem("BK");
    	clientF.getClientYAxisScrollPanel().addItem("BL");
    	clientF.getClientYAxisScrollPanel().addItem("BM");
    	clientF.getClientYAxisScrollPanel().addItem("BN");
    	clientF.getClientYAxisScrollPanel().addItem("BO");
    	clientF.getClientYAxisScrollPanel().setVisible(true);
    	clientF.getClientYAxisScrollPanel().setEnabled(false);
    }
    
    private void setXAxisScrollMenu()
    {
    	clientF.getClientXAxisScrollPanel().removeAllItems();
    	clientF.getClientXAxisScrollPanel().addItem("1");
    	clientF.getClientXAxisScrollPanel().addItem("2");
    	clientF.getClientXAxisScrollPanel().addItem("3");
    	clientF.getClientXAxisScrollPanel().addItem("4");
    	clientF.getClientXAxisScrollPanel().addItem("5");
    	clientF.getClientXAxisScrollPanel().addItem("6");
    	clientF.getClientXAxisScrollPanel().addItem("7");
    	clientF.getClientXAxisScrollPanel().addItem("8");
    	clientF.getClientXAxisScrollPanel().addItem("9");
    	clientF.getClientXAxisScrollPanel().addItem("10");
    	clientF.getClientXAxisScrollPanel().addItem("11");
    	clientF.getClientXAxisScrollPanel().addItem("12");
    	clientF.getClientXAxisScrollPanel().addItem("13");
    	clientF.getClientXAxisScrollPanel().addItem("14");
    	clientF.getClientXAxisScrollPanel().addItem("15");
    	clientF.getClientXAxisScrollPanel().addItem("16");
    	clientF.getClientXAxisScrollPanel().addItem("17");
    	clientF.getClientXAxisScrollPanel().addItem("18");
    	clientF.getClientXAxisScrollPanel().addItem("19");
    	clientF.getClientXAxisScrollPanel().addItem("20");
    	clientF.getClientXAxisScrollPanel().addItem("21");
    	clientF.getClientXAxisScrollPanel().addItem("22");
    	clientF.getClientXAxisScrollPanel().addItem("23");
    	clientF.getClientXAxisScrollPanel().addItem("24");
    	clientF.getClientXAxisScrollPanel().addItem("25");
    	clientF.getClientXAxisScrollPanel().setVisible(true);
    	clientF.getClientXAxisScrollPanel().setEnabled(false);
    }

    private void defaultMap()
    {
    	for (int i = 0; i < 6; i++)
    		maps.add(new ImageApplet());
    }

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		System.out.println(e);
		int player = clientF.getClientMapTabbedPane().getSelectedIndex();
		System.out.println(player + " :: " + e.getX()/10 + " x " + e.getY()/10);
		if(myName.equalsIgnoreCase(
			clientF.getClientMapTabbedPane().getTitleAt(player))){
				System.out.println("HOLY MESS THATS A LONG ONE");
		
			if (e.getButton() == 1)
				{
				if(maps.get(player).AddShip('N', 'V', ((e.getX() / 10)), ((e.getY() / 10))))
					maps.get(player).repaint();
				else
					System.out.println("Error: Ship won't fit there...please try again");
				}
			else if (e.getButton() == 3)
				{
				if(maps.get(player).AddShip('N', 'H', ((e.getX() / 10)), ((e.getY() / 10)))){
					maps.get(player).repaint();
					resetFireAbility();
				}
				else
					System.out.println("Error: Ship won't fit there...please try again");
				}
			}else{
			
			if (e.getButton() == 2)
			{
				
				int tabbedPane = clientF.getClientMapTabbedPane().getSelectedIndex();
				
				String pName = clientF.getClientMapTabbedPane().getTitleAt(tabbedPane);
				
				if(canShoot[tabbedPane]){
					changeAmmoType = false;
					int hits = 0;
					if(weaponSelected == 1)
						hits = maps.get(player).fireShot( pName, 'A', ((e.getX() / 10)), ((e.getY() / 10)));
					else if(weaponSelected == 3)
						hits = maps.get(player).fireShot( pName, 'B', ((e.getX() / 10)), ((e.getY() / 10)));
					else if(weaponSelected == 5)
						hits = maps.get(player).fireShot( pName, 'C', ((e.getX() / 10)), ((e.getY() / 10)));
					else
						System.out.println("Invalid Weapon Choice");
					System.out.println(" # of Hits: " + hits);
					maps.get(player).repaint();
					disableTabPlayer(tabbedPane);
				}
			}
		}
		
	}
	
	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	
	@Override
	public void mouseWheelMoved(MouseWheelEvent arg0) {
		// TODO Auto-generated method stub
		System.out.println(arg0);
		if(changeAmmoType){
			weaponSelected+=2;
			
			if (weaponSelected > 5)
				weaponSelected = 1;

			switch(weaponSelected){
			case 1:
				clientF.getInstance().getClientBombTypeScrollPanel().setSelectedIndex(0);
				break;
			case 3:
				clientF.getInstance().getClientBombTypeScrollPanel().setSelectedIndex(1);
				break;
			case 5:
				clientF.getInstance().getClientBombTypeScrollPanel().setSelectedIndex(2);
				break;
			}
			
			clientF.getInstance().getClientBombTypeScrollPanel().repaint();
			System.out.println("Current Weapon is: " + weaponSelected);
		}
	}

}
